var doTest = true;
// Saves options to localStorage.

// Restores select box state to saved value from localStorage.
function restore_options() {
	$("#username").val(getUsername());
	$("#password").val(getPassword());
}

function save_options(){
	setUsername($("#username").val());
	setPassword($("#password").val());
}

function test(){
	var notification = webkitNotifications.createNotification(
		'icon.png',
		'hello',
		'world');
	notification.show();
}

document.addEventListener('DOMContentLoaded', function(){
	restore_options();
	$("#btn_save").click(function(){
		save_options();
	});
	$("#btn_lasterr").click(function(){
		var le = getLastError();
		if(le){
			if($("#lasterr").length){
				$("#lasterr").remove();
			}
			$("#options").append("<div id='lasterr'><p><h3>Last Error</h3>"
								 + '<strong>Message:</strong><br/>'
								 + '<input type="text" id="lasterrormsg" size="65"></input><br/>'
								 + '<strong>Log</strong><br/>'
								 + '<textarea id="lasterrorlog" cols="64" rows="5"></textarea><br/>'
								 + '<button id="btn_clearlasterr">Clear Last Error</button>'
								 + "</p></div>");
			$("#lasterrormsg").val(le.msg);
			$("#lasterrorlog").val(le.log);
			$("#btn_clearlasterr").click(function(){
				clearLastError();
				$("#lasterr").remove();
			});
		} else {
			alert("No Last Error!");
		}
	});

	if(doTest){
		$("#options").append("<p><button id='btn_test'>Test</button></p>");
		$("#btn_test").click(test);
	}
});